package com.jones.restaurant.utils;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;

public class HttpRequestParams {
	private HttpRequestParams(){}
	public static String getFullUrlParams(String prefixUrl,Map<String,String> httpParams){
		if(httpParams==null){
			return prefixUrl;
		}
		List<BasicNameValuePair> listParams = new LinkedList<BasicNameValuePair>();
		for(Map.Entry<String, String> entry:httpParams.entrySet()){
			listParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
		}
		String fullUrl = "";
		String suffixUrl = URLEncodedUtils.format(listParams, "utf8");
		;
		if(prefixUrl.indexOf('?')==-1){
			fullUrl = prefixUrl+"?"+suffixUrl;
		}else{
			fullUrl = prefixUrl+"&"+suffixUrl;
		}
		return fullUrl;
	}
}
